﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using YArchitech.Revit;

namespace YJKAreaForDraw
{
	public class EdgeFilter : ISelectionFilter
	{
		public EdgeFilter(Autodesk.Revit.DB.Document doc)
		{
			this.m_Doc = doc;
		}

		public bool AllowElement(Element elem)
		{
			return elem is Wall || elem.Category.Id.IntegerValue == -2000586 || elem.Category.Id.IntegerValue == -2000581 || elem.Category.Id.IntegerValue == -2000582 || elem.Category.Id.IntegerValue == -2000035 || elem.Category.Id.IntegerValue == -2000100 || elem.Category.Id.IntegerValue == -2001330 || elem.Category.Id.IntegerValue == -2000032;
		}

		public bool AllowReference(Reference refer, XYZ pos)
		{
			if ((int)refer.ElementReferenceType != 2)
			{
				return (int)refer.ElementReferenceType == 5 || (int)refer.ElementReferenceType == 1;
			}
			Face face = this.m_Doc.GetElement(refer).GetGeometryObjectFromReference(refer) as Face;
			if (null == face)
			{
				return false;
			}
			if (face.GetType() == typeof(PlanarFace))
			{
				PlanarFace face2 = face as PlanarFace;
				if (face2.FaceNormal().IsAlmostEqualTo(XYZ.BasisZ) || face2.FaceNormal().IsAlmostEqualTo(-XYZ.BasisZ))
				{
					return false;
				}
			}
			return true;
		}

		private Document m_Doc;
	}
}
